/**
 * TODO:文件描述
 *
 * @title main
 * @projectName grpcDemo
 * @author niuk
 * @date 2024/4/8 17:54
 */

package main

import (
	rotatelogs "github.com/sauryniu/file-rotatelogs"
	"google.golang.org/grpc/grpclog"
	"grpcDemo/client"
	"grpcDemo/server"
	"time"
)

func init() {
	rpcLogPath := "log/grpc.log"
	rpcLogWriter, err := rotatelogs.New(
		rpcLogPath+".%Y%m%d",                      // 日志文件格式
		rotatelogs.WithLinkName(rpcLogPath),       // 最新日志文件链接名称
		rotatelogs.WithRotationTime(time.Hour*24), // 滚动时间，每24小时
		rotatelogs.WithMaxAge(time.Hour*24*15),    // 日志保存的最长时间，这里是15天
		rotatelogs.WithConsole(),                  // 是否同步打印到控制台
	)
	if err != nil {
		panic(err)
	}
	grpclog.SetLoggerV2(grpclog.NewLoggerV2(rpcLogWriter, rpcLogWriter, rpcLogWriter))

}

func main() {
	go server.Start(":8080")
	// 确保服务开起来
	time.Sleep(time.Second)
	client.Test("etcd://api.grpcdemo.com")
}
